package com.ep.modules.app.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ep.common.utils.PageUtils;
import com.ep.modules.app.dao.AppTaskSheetsMapper;
import com.ep.modules.app.entity.AppTaskSheets;
import com.ep.modules.app.entity.AppTaskSheetsExample;
import com.ep.modules.app.entity.AppTaskSheetsWithBLOBs;
import com.ep.modules.app.service.AppTaskSheetsService;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AppTaskSheetsServiceImpl implements AppTaskSheetsService {
    @Autowired
    private AppTaskSheetsMapper appTaskSheetsMapper;

    public PageUtils queryPage(Map<String, Object> params) {
        String searchKey = (String)params.get("searchKey");
        Long searchUserId = (Long)params.get("searchUserId");
        AppTaskSheetsExample example = new AppTaskSheetsExample();
        AppTaskSheetsExample.Criteria criteria = example.createCriteria();
        List<AppTaskSheets> list = appTaskSheetsMapper.selectByExample(example);
        Page<AppTaskSheets> page = new Page<>();
        page.setRecords(list);
        return new PageUtils(page);
    }

    public AppTaskSheets getById(Long id) {
        return appTaskSheetsMapper.selectByPrimaryKey(id.intValue());
    }

    public void save(AppTaskSheets entity) {
        // 创建 AppTaskSheetsWithBLOBs 对象
        AppTaskSheetsWithBLOBs appTaskSheetsWithBLOBs = new AppTaskSheetsWithBLOBs();

        // 手动复制字段值
        appTaskSheetsWithBLOBs.setTaskSheetId(entity.getTaskSheetId());
        appTaskSheetsWithBLOBs.setAssignmentId(entity.getAssignmentId());
        appTaskSheetsWithBLOBs.setOrderId(entity.getOrderId());
        appTaskSheetsWithBLOBs.setStartLocation(entity.getStartLocation());
        appTaskSheetsWithBLOBs.setEndLocation(entity.getEndLocation());
        appTaskSheetsWithBLOBs.setEstimatedDepartureTime(entity.getEstimatedDepartureTime());
        appTaskSheetsWithBLOBs.setEstimatedArrivalTime(entity.getEstimatedArrivalTime());
        appTaskSheetsWithBLOBs.setStatus(entity.getStatus());
        appTaskSheetsWithBLOBs.setCreatedAt(entity.getCreatedAt());
        appTaskSheetsWithBLOBs.setUpdatedAt(entity.getUpdatedAt());

        appTaskSheetsMapper.insert(appTaskSheetsWithBLOBs);
    }

    public void update(AppTaskSheets entity) {
        // 创建 AppTaskSheetsWithBLOBs 对象
        AppTaskSheetsWithBLOBs appTaskSheetsWithBLOBs = new AppTaskSheetsWithBLOBs();

        // 手动复制字段值
        appTaskSheetsWithBLOBs.setTaskSheetId(entity.getTaskSheetId());
        appTaskSheetsWithBLOBs.setAssignmentId(entity.getAssignmentId());
        appTaskSheetsWithBLOBs.setOrderId(entity.getOrderId());
        appTaskSheetsWithBLOBs.setStartLocation(entity.getStartLocation());
        appTaskSheetsWithBLOBs.setEndLocation(entity.getEndLocation());
        appTaskSheetsWithBLOBs.setEstimatedDepartureTime(entity.getEstimatedDepartureTime());
        appTaskSheetsWithBLOBs.setEstimatedArrivalTime(entity.getEstimatedArrivalTime());
        appTaskSheetsWithBLOBs.setStatus(entity.getStatus());
        appTaskSheetsWithBLOBs.setCreatedAt(entity.getCreatedAt());
        appTaskSheetsWithBLOBs.setUpdatedAt(entity.getUpdatedAt());

        appTaskSheetsMapper.updateByPrimaryKeySelective(appTaskSheetsWithBLOBs);
    }

    public void deleteBatch(Long[] ids) {
        for (Long id : ids) {
                appTaskSheetsMapper.deleteByPrimaryKey(id.intValue());
        }
    }
}